<?php

namespace app\common\model;

use think\Model;


class Seckill extends Model
{

    

    

    // 表名
    protected $name = 'seckill';
    
    // 追加属性
    protected $append = [
        'surplus_at',
        'expect_at',
        'state',
    ];
    
    public function getSurplusAtAttr($value, $data)
    {
        return ($data['endtime'] - time() > 0) ? ($data['endtime'] - time()) : 0;
    }

    public function getExpectAtAttr($value, $data)
    {
        return ($data['starttime'] - time() > 0) ? ($data['starttime'] - time()) : 0;
    }

    public function getStateAttr($value, $data)
    {
        // 1 => '进行中',
        // 2 => '未开始',
        // 3 => '已结束',
        if($data['endtime'] < time()) {
            return 3;
        } elseif($data['starttime'] > time()) {
            return 2;
        } else {
            return 1;
        }
    }


}
